package etxt2db.corpus;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import edu.cmu.minorthird.text.MutableTextBase;
import edu.cmu.minorthird.text.MutableTextLabels;
import edu.cmu.minorthird.text.Tokenizer;

public class MyCompleteTextBaseLoader extends MyTextBaseLoader{
	public MyCompleteTextBaseLoader(List<String> attributes){
		super(attributes);
	}

	/**
	 * Specifies the document style to use, but leaves all other properties to
	 * their defaults.
	 */
	public MyCompleteTextBaseLoader(List<String> attributes, int documentStyle){
		super(attributes,documentStyle);
	}
	
	public MutableTextBase load(File dataLocation) throws IOException,
			ParseException{
		TextBaseLoader secondaryLoader = new TextBaseLoader();
		secondaryLoader.setDocumentStyle(this.documentStyle);
		secondaryLoader.setBeginTag(beginTagString);
		secondaryLoader.setEndTag(endTagString);
		secondaryLoader.load(dataLocation);
		MutableTextLabels secondary = secondaryLoader.getLabels();
		
		if(attributes == null){
			attributes = new ArrayList<String>(secondary.getTypes());
		}
		
		MyTextBaseLoader primaryLoader = new MyTextBaseLoader(attributes);
		primaryLoader.setDocumentStyle(this.documentStyle);
		primaryLoader.setBeginTag(beginTagString);
		primaryLoader.setEndTag(endTagString);
		primaryLoader.load(dataLocation);
		MutableTextLabels primary = primaryLoader.getLabels();
		
		// Create new TextBase and TextLabels to hold the data
		this.labels=new CompleteTextLabels(primary,secondary);
		
		compatiblePartition = primaryLoader.getCompatibleSets();

		return (MutableTextBase) labels.getTextBase();
	}

	public MutableTextBase load(File dataLocation,Tokenizer tok)
			throws IOException,ParseException{
		MyTextBaseLoader primaryLoader = new MyTextBaseLoader(attributes);
		primaryLoader.setDocumentStyle(this.documentStyle);
		primaryLoader.setBeginTag(beginTagString);
		primaryLoader.setEndTag(endTagString);
		primaryLoader.load(dataLocation,tok);
		MutableTextLabels primary = primaryLoader.getLabels();
		
		TextBaseLoader secondaryLoader = new TextBaseLoader();
		secondaryLoader.setDocumentStyle(this.documentStyle);
		secondaryLoader.setBeginTag(beginTagString);
		secondaryLoader.setEndTag(endTagString);
		secondaryLoader.load(dataLocation,tok);
		MutableTextLabels secondary = secondaryLoader.getLabels();
		
		// Create new TextBase and TextLabels to hold the data
		this.labels=new CompleteTextLabels(primary,secondary);
		
		compatiblePartition = primaryLoader.getCompatibleSets();

		return (MutableTextBase) labels.getTextBase();
	}
}
